import { createStore } from 'vuex'

const store = createStore({
  state () {
    return {
      token: '',
      userInfo: {},
      requestUrl: "http://localhost:9000",
      headVisible: true,
      footVisible: false
    }
  },
  mutations: {
    SET_KEY: (state, searchKey) => {
      state.searchKey = searchKey
    },
    SET_TOKEN: (state, token) => {
      state.token = token
      localStorage.setItem('token', token)
    },
    SET_USERINFO: (state, userInfo) => {
      state.userInfo = userInfo
      sessionStorage.setItem('userInfo', JSON.stringify(userInfo))
    },
    SET_HEADVISIBLE: (state, visible) => {
      state.headVisible = visible
    },
    SET_FOOTVISIBLE: (state, visible) => {
      state.footVisible = visible
    },
    REMOVE_INFO: (state) => {
      state.userInfo = {}
      state.token = ''
      localStorage.setItem('token', '')
      sessionStorage.setItem('userInfo', '')
    }
  },
  getters: {
    getUser: state => {
      return JSON.parse(sessionStorage.getItem('userInfo'));
    },
    getSearchKey: state => {
      return state.searchKey
    },
    getRequestUrl: state => {
      return state.requestUrl
    },
    getToken: () => {
      return localStorage.getItem('token')
    },
    getHeadVisible: (state) => {
      return state.headVisible
    },
    getFootVisible: (state) => {
      return state.footVisible
    }
  },
  modules: {
  }
})

export default store
